
var banner;
function Banner() {
  this.backgroundNode = getBackGroundNodeSet();
  this.backgroundNode.style.background = "#CC3333";
  this.backgroundNode.style.MozOpacity = "0.7";
  this.backgroundNode.style.zIndex = 100;

  for (var child = this.backgroundNode.firstChild; 
       child; 
       child = child.nextSibling) {
    child.style.visibility = "hidden";
  }
  
  this.foregroundNode = getForeGroundNodeSet();
  this.foregroundNode.style.zIndex = 101;
   
}

function getBackGroundNodeSet() {
	var boxNode = document.createElement("div");
	with (boxNode.style) {
    display = "none";
    position = "fixed";
    top = "50%";
    left = "10%";
    margin = "0 10% 0 10%";
    width = "60%";
	height = "10%"
    textAlign = "center";
    MozBorderRadius = "10px";
    padding = "10px";
    color = "#CC3333";
  }
  
  return boxNode;
}

function getForeGroundNodeSet() {
	var boxNode = document.createElement("div");
	with (boxNode.style) {
    display = "none";
    position = "fixed";
    top = "50%";
    left = "10%";
    margin = "0 10% 0 10%";
    width = "60%";
    textAlign = "center";
    MozBorderRadius = "10px";
    padding = "10px";
    color = "#CC3333";
  }


  var taglineNode = document.createElement("div");
  with (taglineNode.style) {
    fontSize = "13px";
    margin = "0";
  }
  taglineNode.innerHTML = '<span class="preRegSearch" >Enter Pre-reg code...</span>'+
	  '<form id="preRegCodeForm" action="/ejc/struts/register/registrationUpdateAction.do?" onSubmit="setPreRegCodeValue(this);">'+
	  '<input type="text" name="preRegInput" id="xxx" AUTOCOMPLETE="off" onblur="banner.hide();"/>'+
	  '<input type="hidden" name="methodToCall" value="preRegCodeEntry"/></form>';
  boxNode.appendChild(taglineNode);

 
  return boxNode;

	 
}

Banner.prototype.hide = function() {

	this.backgroundNode.style.display = "none";
    this.foregroundNode.style.display = "none";
	
	
}
Banner.prototype.show = function() {
 
  document.body.appendChild(this.backgroundNode);
  document.body.appendChild(this.foregroundNode);
  this.backgroundNode.style.display = "block";
  this.foregroundNode.style.display = "block";
  window.setTimeout(setFocusOnInput, 30);
  
}
function setFocusOnInput()
{
	//Set the focus on the preRegCode input
  //var preRegCodeForm = document.getElementById('preRegCodeForm');
  //preRegCodeForm.preRegInput.focus();
  //preRegCodeForm.preRegInput.value = "";
  var xxx = document.getElementById('xxx');
  xxx.focus();
  xxx.value = "";
}

function keypress(event)
{
	
	event = event || window.event;

	// Apparently we still see Firefox shortcuts like control-T for a new tab - 
	// checking for modifiers lets us ignore those
	if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
	 return false;
	}
	//alert(event.keyCode);
	  // We also don't want to interfere with regular user typing
	  if (event.target && event.target.nodeName) {
		var targetNodeName = event.target.nodeName.toLowerCase();
		if (targetNodeName == "textarea" || targetNodeName == "select" ||
			(targetNodeName == "input" && event.target.type &&
			 (event.target.type.toLowerCase() == "text" || event.target.type.toLowerCase() == "password"))) {
		  return false;
		}
	  }

	//alert(event.keyCode);
	if(event.keyCode == 82)
	{
		document.location =  'http://'+location.host+'/ejc/struts/register/registrationAction.do?methodToCall=preCreate';

	}else if(event.keyCode == 80){
			
			banner = new Banner();
			banner.show();	
	
	}else if(event.keyCode == 83){
			document.location = 'http://'+location.host+'/ejc/struts/search/searchRegistrantsAction.do?methodToCall=preSearch';

	}else if(event.keyCode == 68){
			document.location = 'http://'+location.host+'/ejc/struts/dashboard/dashboardAction.do?methodToCall=loadDash';
	}else if(event.keyCode == 69){
			document.location = 'http://'+location.host+'/ejc/struts/admin/createExecutiveAction.do?methodToCall=preCreateExec';
	}else if(event.keyCode == 67){
			document.location = 'http://'+location.host+'/ejc/struts/register/specialPaymentsAction.do?methodToCall=preSpecialPayment';
	}
	else if(event.keyCode == 84){
			document.location = 'http://'+location.host+'/ejc/struts/statistics/statistics.jsp';
	}

}

  // We also don't want to interfere with regular user typing
  //if (event.target && event.target.nodeName) {
 //   var targetNodeName = event.target.nodeName.toLowerCase();
 //   if (targetNodeName == "textarea" ||
 //       (targetNodeName == "input" && event.target.type &&
 //        event.target.type.toLowerCase() == "text")) {
 //     return false;
 //   }
 // }

document.addEventListener( 'keydown', keypress, false );
/*
* Load a new page. This is a generic function that loads a new page when a menu option is selected
*/
function loadPage(pageURL)
{
	window.location = 'http://'+location.host+pageURL;
}

/*
* Utility to get an element by its ID.
* id: The id of the element that is being retrieved
*/
function get(id)
{
	return document.getElementById(id);
}

function hideShortcuts()
{
	var shortcutsDiv = get('shortcutsDivId');
	document.body.removeChild(shortcutsDiv);
}

/*Only works in Mozilla. Need to cater for Fecking IE. Stupid Microsoft.*/
function showShortcuts()
{
	
	var shortcutsDiv = document.createElement('DIV');
	shortcutsDiv.id = 'shortcutsDivId';
	//Esc will lose focus and close it. Need an input field to focus on.
	with (shortcutsDiv.style) {
    display = "block";
    position = "fixed";
	visibility = "visible";
    top = "8%";
    left = "41%";
    margin = "0 10% 0 10%";
    width = "30%";
    textAlign = "center";
    MozBorderRadius = "10px";
    padding = "10px";
    color = "#000";
	background = "#EE8800";
	
	zIndex = 1000;
	}
	var shortHTML = '<table width="100%" bgColor="#FADCB3"><tr><td align=\"center\" class=\"shortcutsTitle\">Keyboard Shortcuts</td><td align=\"right\"><img class="pointerhand" src="../../img/close.gif" onclick="javascript:hideShortcuts();"></td>'
					+'<tr><td align=\"left\" class=\"shortcutsText\">r - Register Guest</td></tr><tr><td align=\"left\"  class=\"shortcutsText\">s - Search Guests</td></tr><tr><td align=\"left\"  class=\"shortcutsText\">p - Pre-Registration Search</td></tr>'
					+'<tr><td align=\"left\"  class=\"shortcutsText\">d - Dashboard</td></tr><tr><td align=\"left\"  class=\"shortcutsText\">e - Add Executive</td></tr>'
					+'<tr><td align=\"left\"  class=\"shortcutsText\">c - Solas Circus</td></tr>'
					+'<tr><td align=\"left\"  class=\"shortcutsText\">t - Statistics</td></tr>'
					+'</table>';
	shortcutsDiv.innerHTML = shortHTML;
	document.body.appendChild(shortcutsDiv);
	
}

/**
* Retricts chars from being entered into the input field.
* Only digits, backspace and decimal place allowed.
**/
function noChars(e)
{
     var keynum
     var keychar
     var numcheck
     
     if(window.event) // IE
     {
     keynum = e.keyCode
     }
     else if(e.which) // Netscape/Firefox/Opera
     {
     keynum = e.which
     }
     keychar = String.fromCharCode(keynum)
     numcheck = /\d/;
	 
	 //Allows backspace and decimal place to be added. Everything else except digits are resticted
	 if(e.which == 8 || e.which == 46 || e.which == 0){
		return;	 
	 }else{
		return numcheck.test(keychar)
	 }
     
}

/**
* Disable the back button by moving the history forward by 1
**/
function disableBackButton(){
		//alert('testing');
		window.history.forward(1);
	}